﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.CJL.API.Application.Command.FinishedProductsCommand;
using System.CJL.API.DTO;
using System.CJL.Domain;
using System.CJL.Domain.DTO;
using System.Collections.Generic;

namespace System.CJL.API.Controllers
{
	/// <summary>
	/// 成品控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
    [Authorize]
    public class FinishedProductsController : ControllerBase
	{
		IMediator _mediator;
        public FinishedProductsController(IMediator mediator)
        {
			_mediator=mediator;
		}
		/// <summary>
		/// 成品显示
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<PageDTO<FinishedProduct>>> FinishedProductsShow([FromQuery] FinishedProductsShowCommand t)
		{
			ApiResult<PageDTO<FinishedProduct>> result = new ApiResult<PageDTO<FinishedProduct>>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 显示屁
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<List<FinishedProduct>>> ShowFinis(FinishedProductsPiShowCommand t)
        {
            ApiResult<List<FinishedProduct>> result = new ApiResult<List<FinishedProduct>>();

            try
            {
                result.Data = await _mediator.Send(t);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 成品添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
		public async Task<ApiResult<int>> FinishedProductsAdd(FinishedProductsAddCommand t)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 成品返填
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<FinishedProduct>> FinishedProductsMondel([FromQuery] FinishedProductsMondelCommand t)
		{
			ApiResult<FinishedProduct> result = new ApiResult<FinishedProduct>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 成品修改
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> FinishedProductsUpdate(FinishedProductsUpdateCommand t)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 成品删除
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> FinishedProductsDelete(FinishedProductsDeleteCommand t)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 成品批量删除
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> FinishedProductsDeletePi(FinishedProductsDeletePiCommand t)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(t);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}

		
    }
}
